package com.adapter;

import com.duck.Duck;
import com.duck.Turkey;

/**
 * @author SnowmanAndBee
 * @version <version>
 * 对象适配器，将火鸡变成鸭子
 * 适配器还有一种为类适配器，需要多继承，Java无法实现
 * @date 2022/4/5 - 16:19
 */
public class TurkeyAdapter implements Duck {
    Turkey turkey;

    public TurkeyAdapter(Turkey turkey) {
        this.turkey = turkey;
    }

    @Override
    public void quack() {
        turkey.gobble();
    }

    @Override
    public void fly() {
        //飞5次达到鸭子飞的距离
        for (int i = 0; i < 5; i++) {
            turkey.fly();
        }
    }
}
